import { getUserGuideStorageFor, creatServerCachApi } from '@src/api/GuideApi';

export default {
  name: 'layout-mixin',
  data() {
    return {
      baseLayout: 2, // 需要从接口里获取当前租户的设置
    }
  },
  computed: {
    baseLayoutStorageType() {
      return `${this.loginUser?.userId}-multi-row`
    }
  },
  methods: {
    setBaseLayoutStorage() {
      const params = { 
        isComplete: 1,
        step: 1,
        type: this.baseLayoutStorageType,
        userConfig: JSON.stringify({ baseLayout: this.baseLayout })
      }
      creatServerCachApi(params)
    },
    getBaseLayoutStorage() {
      if(!this.loginUser?.userId) return
      getUserGuideStorageFor({ type: this.baseLayoutStorageType }).then(res => {
        if(!res.succ) return
        const userConfig = JSON.parse(res?.data?.userConfig) ?? {}
        this.baseLayout = userConfig.baseLayout || 2
      }).catch(error => {
        console.error(error)
      })
    }
  },
}